package com.caseProject.puremvc.mediator.view
{
	import com.caseProject.puremvc.mediator.gui.AbstractDiagramMenu;
	import com.caseProject.puremvc.mediator.events.MenuStateEvent;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class MenuStateView extends AbstractDiagramMenu
	{
		private var view:MenuStateSWC;
		
		public function MenuStateView()
		{
			super();
			
			this.view = new MenuStateSWC();
			this.addChild(this.view);
			
			this.view.btnState.addEventListener(MouseEvent.CLICK, onStateClick);
			this.view.btnStart.addEventListener(MouseEvent.CLICK, onStartClick);
			this.view.btnEnd.addEventListener(MouseEvent.CLICK, onEndClick);
			this.view.btnNote.addEventListener(MouseEvent.CLICK, onNoteClick);
			this.view.btnTransition.addEventListener(MouseEvent.CLICK, onTransitionClick);
			this.view.btnSelect.addEventListener(MouseEvent.CLICK, onSelectClick);
			
			this.addEventListener(Event.ADDED_TO_STAGE, onInit);
		}
		
		protected function onInit(event:Event):void
		{			
			this.stage.addEventListener (Event.RESIZE, onResize);
			this.view.fundo.width = this.stage.stageWidth - this.view.x;
		}
		
		protected function onResize(event:Event):void
		{
			if (this.stage != null)
			{
				this.view.fundo.width = this.stage.stageWidth - this.view.x;
			}
		}
		
		protected function onSelectClick(event:MouseEvent):void
		{
			this.dispatchEvent(new MenuStateEvent(MenuStateEvent.CLICK_SELECT));
		}
		
		protected function onTransitionClick(event:MouseEvent):void
		{
			this.dispatchEvent(new MenuStateEvent(MenuStateEvent.CLICK_TRANSITION));
		}
		
		protected function onNoteClick(event:MouseEvent):void
		{
			this.dispatchEvent(new MenuStateEvent(MenuStateEvent.CLICK_NOTE));
		}
		
		protected function onEndClick(event:MouseEvent):void
		{
			this.dispatchEvent(new MenuStateEvent(MenuStateEvent.CLICK_END));			
		}
		
		protected function onStartClick(event:MouseEvent):void
		{
			this.dispatchEvent(new MenuStateEvent(MenuStateEvent.CLICK_START));						
		}
		
		protected function onStateClick(event:MouseEvent):void
		{
			this.dispatchEvent(new MenuStateEvent(MenuStateEvent.CLICK_STATE));
		}
	}
}